#include <iostream>
#include <signal.h>
#include <unistd.h>
using namespace std;

void PrintPending(const sigset_t& pending)
{
    for(int signo = 31; signo > 0; signo--)
    {
        if(sigismember(&pending, signo))
        {
            cout << "1";
        }
        else
        {
            cout << "0";
        }
    }
    cout << endl;
}

void handler(int signo)
{
    cout << "get a signo : " << signo << endl;
    sleep(1);
}

int main()
{
    signal(2, handler);
    signal(3, handler);
    signal(4, handler);
    signal(5, handler);
    sigset_t mask, omask;
    sigemptyset(&mask);
    sigemptyset(&omask);
    sigaddset(&mask, 2);
    sigaddset(&mask, 3);
    sigaddset(&mask, 4);
    sigaddset(&mask, 5);
    sigprocmask(SIG_SETMASK, &mask, &omask);

    cout << "getpid :" << getpid() << endl;
    int cnt = 20;
    while(true)
    {
        sigset_t pending;
        sigpending(&pending);
        PrintPending(pending);
        cnt--;
        sleep(1);
        if(cnt == 0)
        {
            sigprocmask(SIG_SETMASK, &omask, nullptr);
            cout << "cancel 2,3,4,5 block" << endl;
        }
    }
    return 0;
}